/* HPAudit: Always use strict mode : hp-specs-use-strict-mode : 1 : 0 : issue484.ts */
"use strict";
import hilog from '@ohos.hilog';
import { describe, it, expect } from '@ohos/hypium'
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import { Driver, ON } from '@ohos.UiTest';
const DRIVER = Driver.create();

// 结果需要使用aa工具查看，这里仅测试UI部分是否展示正常
export default function abilityTest() {
  /* HPAudit: Do not dynamically declare functions and classes : hp-performance-no-dynamic-cls-func : 1 : 10 : issue484.ts */
  describe('ActsAbilityTest', function() {
    it('StartAbility_001', 0, async function(done) {
      hilog.info(0xF811, 'testTag', 'StartAbility_001 begin');
      /* HPAudit: Declare unchanged variables as const : hp-performance-unchanged-const-vars : 1 : 14 : issue484.ts */
      const abilityDelegatorRegistry = AbilityDelegatorRegistry.getAbilityDelegator();
      try {
        await abilityDelegatorRegistry.startAbility({ 
          bundleName: 'ohos.samples.startmode',
          abilityName: 'MainAbility'
        });
        done();
      }
      catch (err) {
        expect(0).assertEqual(err.code);
        done();
      }
      hilog.info(0xF811, 'testTag', 'StartAbility_001 end');
    })
    it('CheckPage_001', 0, async function() {
      hilog.info(0xF811, 'testTag', 'CheckPage_001 begin');
      await DRIVER.delayMs(1000);
      // 检查是否存在这三个板块
      await DRIVER.assertComponentExist(ON.text('普通多实例'));
      await DRIVER.assertComponentExist(ON.text('指定多实例'));
      await DRIVER.assertComponentExist(ON.text('单实例'));
      hilog.info(0xF811, 'testTag', 'CheckPage_001 end');
    })
    it('CheckDetailPage_001', 0, async function() {
      hilog.info(0xF811, 'testTag', 'CheckDetailPage_001 begin');
      await DRIVER.delayMs(1000);
      // 点击番茄
      await DRIVER.assertComponentExist(ON.text('番茄'));
      /* HPAudit: Declare unchanged variables as const : hp-performance-unchanged-const-vars : 1 : 43 : issue484.ts */
      const tomato = await DRIVER.findComponent(ON.text('番茄'));
      await tomato.click();
      await DRIVER.delayMs(1000);
      // 断言存在text为番茄的组件
      await DRIVER.assertComponentExist(ON.text('番茄'));
      await DRIVER.assertComponentExist(ON.id('ContentTable'));
      /* HPAudit: Declare unchanged variables as const : hp-performance-unchanged-const-vars : 1 : 49 : issue484.ts */
      const contentTable = await DRIVER.findComponent(ON.id('ContentTable'));
      /* HPAudit: Declare unchanged variables as const : hp-performance-unchanged-const-vars : 1 : 50 : issue484.ts */
      const contentTablePoint = await contentTable.getBoundsCenter();
      // 向左滑动
      await DRIVER.fling({ 
        x: contentTablePoint.x + 200,
        y: contentTablePoint.y
      }, { 
        x: contentTablePoint.x - 200,
        y: contentTablePoint.y
      }, 50, 200);
      await DRIVER.delayMs(1000);
      await DRIVER.assertComponentExist(ON.id('CaloriesProgress'));
      await DRIVER.assertComponentExist(ON.id('detailPage'));
      /* HPAudit: Declare unchanged variables as const : hp-performance-unchanged-const-vars : 1 : 60 : issue484.ts */
      const detailPage = await DRIVER.findComponent(ON.id('detailPage'));
      /* HPAudit: Declare unchanged variables as const : hp-performance-unchanged-const-vars : 1 : 61 : issue484.ts */
      const detailPagePoint = await detailPage.getBoundsCenter();
      // 向下滑动
      await DRIVER.fling({ 
        x: detailPagePoint.x,
        y: detailPagePoint.y + 100
      }, { 
        x: detailPagePoint.x,
        y: detailPagePoint.y - 100
      }, 100, 200);
      await DRIVER.assertComponentExist(ON.text('黄瓜'));
      hilog.info(0xF811, 'testTag', 'CheckDetailPage_001 end');
    })
    it('CheckDetailPage_002', 0, async function() {
      hilog.info(0xF811, 'testTag', 'CheckDetailPage_002 begin');
      // 点击黄瓜
      await DRIVER.delayMs(1000);
      /* HPAudit: Declare unchanged variables as const : hp-performance-unchanged-const-vars : 1 : 76 : issue484.ts */
      const cucumber = await DRIVER.findComponent(ON.text('黄瓜'));
      await cucumber.click();
      await DRIVER.assertComponentExist(ON.text('黄瓜'));
      await DRIVER.assertComponentExist(ON.text('Food Detail'));
      hilog.info(0xF811, 'testTag', 'CheckDetailPage_002 end');
    })
  })
}
